# -*- UTF-8 -*-
import pandas as pd


def parse_everymonth_csv(year):
    start = year + "-01"
    end = year + "-12"
    period = pd.period_range(start=start, end=end, freq='M')
    periods_strs = []

    for p in period:
        periods_strs.append(str(p))
    df = pd.read_csv(start+".csv")
    # Drop blank row
    df2 = df.drop(df.index[-1])
    # Add periods column
    df2['periods'] = periods_strs

    df2.to_csv(start+"new.csv", sep=',', index=False)
    print("Succeed!")


def merge_csv():
    months = ["2009-01", "2010-01", "2011-01", "2012-01",
          "2013-01", "2014-01", "2015-01", "2016-01", "2017-01", "2018-01"]
    all_data = pd.read_csv("2008-08new.csv")

    for month in months:
        df = pd.read_csv(month + "new.csv")
        all_data = all_data.append(df)

    all_data.to_csv("tags_trend.csv", sep=',', index=False)


def add_tags_sum_col():
    all_data = pd.read_csv("tags_trend.csv")
    # remove "periods" column
    temp_df = all_data.drop(columns=['periods'])
    # get row_sum column values
    row_tags_sum = []
    for row in temp_df.values:
        sum = 0
        for val in row:
            sum += val
        row_tags_sum.append(sum)
    # add row_tags_sum column
    all_data['row_tags_sum'] = row_tags_sum
    all_data.to_csv("tags_trend_new.csv", sep=',', index=False)
    print("Succeed!!!")


if __name__ == '__main__':
    # add_tags_sum_col()